package io.github.uicdb.badskill;

import com.google.common.collect.Maps;
import com.google.gson.JsonElement;
import io.github.uicdb.badskill.codec.JsonFactory;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener;
import net.minecraft.util.profiling.ProfilerFiller;

import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;

public class SkillOptionManager extends SimpleJsonResourceReloadListener {
    public static final SkillOptionManager INSTANCE=new SkillOptionManager();
    public final HashMap<ResourceLocation,SkillOption> OPTIONS =new HashMap<>();
    public  Map<ResourceLocation,SkillOption> exceptionsOptions=new HashMap<>();

    public SkillOptionManager() {
        super(JsonFactory.create(),"skill_option");
    }

    @Override
    protected void apply(Map<ResourceLocation, JsonElement> elementMap, ResourceManager pResourceManager, ProfilerFiller pProfiler) {
        exceptionsOptions.clear();
        HashMap<ResourceLocation, SkillOption> temp = new HashMap<>(OPTIONS);
        OPTIONS.clear();
        elementMap.forEach((resourceLocation, element) -> {
            SkillOption option = SkillOption.fromJson(element);
            OPTIONS.put(option.id, option);
        });
        exceptionsOptions=new HashMap<>(Maps.difference(OPTIONS,temp).entriesOnlyOnRight());
    }
}
